<?php
if(INSTALLING == TRUE)
{

$databaseinfo['host'] = $data['db_host'];
$databaseinfo['user'] = $data['db_user'];
$databaseinfo['password'] = $data['db_password'];
$databaseinfo['dbname'] = $data['db_name'];


include("../inc/errors.php");   // include error profiles



//connect to mysql database for all files
$mysql['connection'] = mysql_connect($databaseinfo['host'], $databaseinfo['user'], $databaseinfo['password'])
or die ($error['connection']);

//select mysql database
$mysql['db'] = mysql_select_db($databaseinfo['dbname'],$mysql['connection'])
or die ($error['database']);



$sql = 'CREATE TABLE IF NOT EXISTS `articles` (
  `id` int(25) NOT NULL auto_increment,
  `article_title` varchar(100) NOT NULL,
  `article_subtitle` varchar(100) NOT NULL,
  `article_author` varchar(100) NOT NULL,
  `article_cat` varchar(15) NOT NULL,
  `article_text` varchar(20000) NOT NULL,
  `article_exptext` varchar(20000) NOT NULL,
  `article_imgid` varchar(100) NOT NULL,
  `allow_comments` varchar(1) NOT NULL,
  `start_date` varchar(15) NOT NULL,
  `end_date` varchar(15) NOT NULL,
  `active` varchar(1) NOT NULL,
  `approved` varchar(1) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `article_title` (`article_title`,`timestamp`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
$res = mysql_query($sql);


$sql = 'CREATE TABLE IF NOT EXISTS `banlist` (
  `id` int(10) NOT NULL auto_increment,
  `ip` varchar(15) NOT NULL,
  `banned_by` varchar(20) NOT NULL,
  `reason` varchar(5000) NOT NULL,
  `timestamp` varchar(12) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(15) NOT NULL auto_increment,
  `cat_name` varchar(100) NOT NULL,
  `cat_parent` varchar(10000) NOT NULL,
  `cat_author` varchar(100) NOT NULL,
  `cat_desc` varchar(1000) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `comments` (
  `id` int(25) NOT NULL auto_increment,
  `article_id` varchar(25) NOT NULL,
  `comment_text` varchar(1000) NOT NULL,
  `comment_author` varchar(20) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `approved` varchar(1) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `cookielog` (
  `id` int(20) NOT NULL auto_increment,
  `user_id` varchar(15) NOT NULL,
  `rank_id` varchar(15) NOT NULL,
  `cookie_id` varchar(32) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `gconfig` (
  `id` int(5) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `v1` varchar(5) NOT NULL,
  `v2` varchar(5) NOT NULL,
  `v3` varchar(1000) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `help` (
  `id` int(5) NOT NULL auto_increment,
  `topic_title` varchar(100) NOT NULL,
  `topic_text` varchar(5000) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `images` (
  `id` int(15) NOT NULL auto_increment,
  `user_id` varchar(15) NOT NULL,
  `image_filepath` varchar(500) NOT NULL,
  `alt_description` varchar(100) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `ranks` (
  `id` int(15) NOT NULL auto_increment,
  `rank_title` varchar(100) NOT NULL,
  `rank_desc` varchar(1000) NOT NULL,
  `rank_author` varchar(100) NOT NULL,
  `permissions` varchar(100) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `templates` (
  `id` int(15) NOT NULL auto_increment,
  `template_name` varchar(100) NOT NULL,
  `template_desc` varchar(1000) NOT NULL,
  `template_author` varchar(100) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `html_article` varchar(5000) NOT NULL,
  `html_comment` varchar(5000) NOT NULL,
  `html_form` varchar(5000) NOT NULL,
  `template_selected` varchar(1) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `themes` (
  `id` int(10) NOT NULL auto_increment,
  `theme_name` varchar(100) NOT NULL,
  `theme_author` varchar(100) NOT NULL,
  `theme_dir` varchar(200) NOT NULL,
  `base_dir` varchar(50) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `theme_selected` varchar(1) NOT NULL,
  `permissions` varchar(10000) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `userlogin` (
  `id` int(20) NOT NULL auto_increment,
  `username` varchar(15) NOT NULL,
  `rank_id` varchar(15) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `user_id` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=82 ;
';
$res = mysql_query($sql);

$sql = 'CREATE TABLE IF NOT EXISTS `users` (
  `id` int(15) NOT NULL auto_increment,
  `user_name` varchar(100) NOT NULL,
  `full_name` varchar(150) NOT NULL,
  `email` varchar(100) NOT NULL,
  `password` varchar(40) NOT NULL,
  `timestamp` varchar(15) NOT NULL,
  `ip` varchar(15) NOT NULL,
  `msn` varchar(100) NOT NULL,
  `aim` varchar(100) NOT NULL,
  `yahoo` varchar(100) NOT NULL,
  `skype` varchar(100) NOT NULL,
  `display_picture` varchar(150) NOT NULL,
  `rank_id` varchar(15) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;';
$res = mysql_query($sql);

$sql = "INSERT INTO `articles` (`id`, `article_title`, `article_subtitle`, `article_author`, `article_cat`, `article_text`, `article_exptext`, `article_imgid`, `allow_comments`, `start_date`, `end_date`, `active`, `approved`, `timestamp`, `ip`) VALUES (NULL, 'Welcome to phpns!','','" . $data['username'] . "','all','&lt;p&gt;If you see are viewing this message, the phpns installation was a success! This article is filed under &amp;quot;Site Wide News&amp;quot;, which is the default category that is created during installation.&lt;/p&gt;&lt;p&gt;&lt;font color=&quot;#993300&quot;&gt;You are free to modify this message, or delete it all together&lt;/font&gt;. Why should you use phpns?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;It&#039;s free&lt;/strong&gt;. Phpns is released under the GPL license, which gives you the ability to change it, redistribute it, and use it personally or professionally.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s clean&lt;/strong&gt;. It&#039;s a breath or fresh air, following web standards and semantics. The (open-source) code is neatly organized, logically indented, and well-commented to make changes easier.&lt;/li&gt;&lt;li&gt;I&lt;strong&gt;t&#039;s easy to integrate&lt;/strong&gt;. Only one line of code is necessary on your website, and you have a dynamic, fully functional news system. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s easy to install&lt;/strong&gt;. The guided installation will have you up and running in minutes, asking you just a few questions about your database setup.&lt;/li&gt;&lt;/ul&gt;Some more information is available in the &amp;quot;Full Article&amp;quot; section...','What does &amp;quot;free&amp;quot; mean? &lt;blockquote&gt;To the phpns developers, the word &amp;quot;free&amp;quot; means more than just the cost of the product. The word free means that &lt;strong&gt;you are free&lt;/strong&gt; to modify anything you want about phpns, without any license restrictions.&lt;/blockquote&gt;&lt;p&gt;Why is phpns free in both price and modification?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we believe in the open-source message. Closed source applications restrict the user from customizing the way the system works, and prevents the communitiy from contributing to the package. Plus, we love seeing our software being put to good use, and we love modifications.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Why don&#039;t you require a &amp;quot;Powered by phpns&amp;quot; message at the bottom of each page, like other news systems?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we hated that when using other products... and the fact that you had to pay to have it removed. However, if you don&#039;t mind a message like that, it can be enabled in the preferences system. It&#039;s disabled by default.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;What can I do to help the project?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you would like to be a part of the project, we always appreciate help. What you can do:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Spread the word. Recommend our system to your friends and co-workers!&lt;/li&gt;&lt;li&gt;Report bugs you&#039;ve encountered at the &lt;a href=&quot;http://launchpad.net/phpns&quot;&gt;phpns launchpad website&lt;/a&gt;. &lt;/li&gt;&lt;li&gt;Submit reviews to software review websites around the internet. As long as they are honest, this is a great way to help us.&lt;/li&gt;&lt;li&gt;Donate. This helps with hosting/domain costs, and you&#039;ll get your name on the website along with a message and URL of your blog/website.&lt;/li&gt;&lt;li&gt;Become a sponsor. If you&#039;re a hosting service, business, or organization, we&#039;re always looking for funding and bandwith.&lt;/li&gt;&lt;li&gt;Develop. Contact us on the website if you think we could use your services.&lt;/li&gt;&lt;/ul&gt;That&#039;s it. Enjoy phpns!&lt;br /&gt;&lt;/blockquote&gt;','imgid','0','','','1','1','".time()."','".$_SERVER['REMOTE_ADDR']."')";
$res = mysql_query($sql);

$sql = "INSERT INTO `gconfig` (`id`, `name`, `v1`, `v2`, `v3`) VALUES 
(1, 'siteonline', '0', '0', '0'),
(2, 'def_rsslimit', '', '', '3'),
(3, 'def_rssorder', 'desc', '', ''),
(4, 'def_rsstitle', '', '', 'kj'),
(5, 'def_rssdesc', '', '', 'lkj'),
(6, 'def_rssenabled', '1', '', ''),
(7, 'def_limit', '10', '', ''),
(8, 'def_order', 'desc', '', ''),
(9, 'def_offset', '0', '', ''),
(10, 'timestamp_format', '', '', 'D M d, Y'),
(11, 'def_comlimit', '', '', '100000'),
(12, 'def_comenabled', '1', '', ''),
(13, 'def_comorder', 'asc', '', ''),
(14, 'global_message', '', '', '<strong>Welcome</strong> to the phpns administration panel. You are using phpns the alpha 1 release.');";
$res = mysql_query($sql);

$sql = "INSERT INTO `ranks` (`id`, `rank_title`, `rank_desc`, `rank_author`, `permissions`, `timestamp`) VALUES 
(1, 'Administrators', 'Any user assigned to this rank will have full access.', '" . $data['username'] . "', '1,1,1,1,1,1,1,1,1,1,1,1', '" . time() ."');";
$res = mysql_query($sql);

$sql = "INSERT INTO `themes` (`id`, `theme_name`, `theme_author`, `theme_dir`, `base_dir`, `timestamp`, `theme_selected`, `permissions`) VALUES 
(NULL, 'default', 'phpns team', 'themes/default/', 'default', '" . time() ."', '1', '');";
$res = mysql_query($sql);

$sql = "INSERT INTO `users` (`id`, `user_name`, `full_name`, `email`, `password`, `timestamp`, `ip`, `msn`, `aim`, `yahoo`, `skype`, `display_picture`, `rank_id`) VALUES 
(NULL, '" . $data['username'] . "', '" . $data['username'] . "', '', '" . $data['password'] ."', '" . time() ."', '127.0.0.1', '', '', '', '', '', '1');";
$res = mysql_query($sql);

$sql = 'INSERT INTO `gconfig` (`id`, `name`, `v1`, `v2`, `v3`) VALUES (NULL, \'siteonline\', \'0\', \'0\', \'0\');';
$res = mysql_query($sql);

$sql = 'INSERT INTO `categories` (`id`, `cat_name`, `cat_parent`, `cat_author`, `cat_desc`, `timestamp`, `ip`) VALUES (NULL, \'Site news\', \'\', \''. $data['username'] .'\', \'This is for general news on your website.\', \''.time().'\', \''. $_SERVER['REMOTE_ADDR'].'\');';
$res = mysql_query($sql);
}
?>
